#ifndef _WX_RICHTEXTHTML_H_
#define _WX_RICHTEXTHTML_H_

#include "wx/richtext/richtextbuffer.h"

#define wxRICHTEXT_HANDLER_USE_CSS 0x1000

class wxRichTextHTMLHandler: public wxRichTextFileHandler {
    DECLARE_CLASS( wxRichTextHTMLHandler )
  public:
    wxRichTextHTMLHandler( const wxString& name = wxT( "HTML" ), const wxString& ext = wxT( "html" ), int type = wxRICHTEXT_TYPE_HTML );


    virtual bool CanSave() const { return true; }


    virtual bool CanLoad() const { return false; }


    virtual bool CanHandle( const wxString& filename ) const;
    void SetTemporaryImageLocations( const wxArrayString& locations ) { m_imageLocations = locations; }
    const wxArrayString& GetTemporaryImageLocations() const { return m_imageLocations; }


    void ClearTemporaryImageLocations() { m_imageLocations.Clear(); }


    bool DeleteTemporaryImages();




    static bool DeleteTemporaryImages( int flags, const wxArrayString& imageLocations );


    static void SetFileCounter( int counter ) { sm_fileCounter = counter; }



    void SetTempDir( const wxString& tempDir ) { m_tempDir = tempDir; }
    const wxString& GetTempDir() const { return m_tempDir; }




    void SetFontSizeMapping( const wxArrayInt& fontSizeMapping ) { m_fontSizeMapping = fontSizeMapping; }
    wxArrayInt GetFontSizeMapping() const { return m_fontSizeMapping; }

  protected:



    #if wxUSE_STREAMS
    virtual bool DoLoadFile( wxRichTextBuffer *buffer, wxInputStream& stream );
    virtual bool DoSaveFile( wxRichTextBuffer *buffer, wxOutputStream& stream );


    void BeginCharacterFormatting( const wxTextAttrEx& currentStyle, const wxTextAttrEx& thisStyle, const wxTextAttrEx& paraStyle, wxTextOutputStream& stream );
    void EndCharacterFormatting( const wxTextAttrEx& currentStyle, const wxTextAttrEx& thisStyle, const wxTextAttrEx& paraStyle, wxTextOutputStream& stream );


    void BeginParagraphFormatting( const wxTextAttrEx& currentStyle, const wxTextAttrEx& thisStyle, wxTextOutputStream& stream );
    void EndParagraphFormatting( const wxTextAttrEx& currentStyle, const wxTextAttrEx& thisStyle, wxTextOutputStream& stream );


    void OutputFont( const wxTextAttrEx& style, wxTextOutputStream& stream );


    void CloseLists( int level, wxTextOutputStream& str );


    void WriteImage( wxRichTextImage* image, wxOutputStream& stream );


    long PtToSize( long size );


    wxChar* b64enc( unsigned char* input, size_t in_len );


    const wxChar* GetMimeType( int imageType );


    wxString GetAlignment( const wxTextAttrEx& thisStyle );


    wxString SymbolicIndent( long indent );


    int TypeOfList( const wxTextAttrEx& thisStyle, wxString& tag );
    #endif



    wxRichTextBuffer* m_buffer;


    wxArrayInt      m_indents;


    wxArrayInt      m_listTypes;


    bool            m_font;


    bool            m_inTable;


    wxArrayString   m_imageLocations;


    wxString        m_tempDir;


    wxArrayInt      m_fontSizeMapping;


    static int      sm_fileCounter;
};

#endif
